home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_psutils.idb / usr / freeware / bin / fixdlsrps.z / fixdlsrps
Encoding:
Text File  |  1999-07-16  |  1.5 KB  |  58 lines

  1. #!/usr/freeware/bin/perl
  2. eval 'exec perl -S $0 "$@"'
  3.     if $running_under_some_shell;
  4.  
  5. # fixdlsrps: fix DviLaser/PS document to work with PSUtils
  6. #
  7. # Copyright (C) Angus J. C. Duggan 1991-1995
  8. # See file LICENSE for details.
  9.  
  10. $nesting = 0;
  11. $page = 1;
  12. $infont = 0;
  13.  
  14. @fonts = ();
  15. @body = ();
  16. $header = 1;
  17.  
  18. while (<>) {
  19.    if (/^XP/) {
  20.       $infont++;
  21.       push(@fonts, $_);
  22.       $infont-- if /PXL.*RP/ || /DN?F.*RP/;
  23.    } elsif ($infont) {
  24.       push(@fonts, $_);
  25.       $infont-- if /PXL.*RP/ || /DN?F.*RP/;
  26.    } elsif ((/^%%EndSetup/ || /^%%Page:/) && $header) {
  27.       print @body;
  28.       @body = ("%%EndSetup\n");
  29.       $header = 0;
  30.    } elsif (/^%%EndProlog/ && !$nesting) {
  31.       push(@body,
  32.        "\$DviLaser begin/GlobalMode{}bdef/LocalMode{}bdef/XP{}def/RP{}def",
  33.        "/DoInitialScaling{72.0 Resolution div dup scale}bdef end\n", $_);
  34.    } elsif (/^%%BeginPageSetup/ && !$nesting) {
  35.       push(@body, "%%Page: $page $page\n", $_,
  36.         "Resolution 72 div dup scale Magnification 1000 div dup scale\n",
  37.         "/DocumentInitState where {\n",
  38.         "/DocumentInitState [ matrix currentmatrix currentlinewidth",
  39.         " currentlinecap currentlinejoin currentdash currentgray",
  40.         " currentmiterlimit] cvx put}if\n");
  41.       $page++;
  42.    } elsif (/^%%BeginDocument:/ || /^%%BeginBinary:/ || /^%%BeginFile:/) {
  43.       push(@body, $_);
  44.       $nesting++;
  45.    } elsif (/^%%EndDocument/ || /^%%EndBinary/ || /^%%EndFile/) {
  46.       push(@body, $_);
  47.       $nesting--;
  48.    } elsif (!/^%%PageBoundingBox:/ && !/^%%Page:/) {
  49.       push(@body, $_);
  50.    }
  51. }
  52.  
  53. print @fonts;
  54. print @body;
  55.  
  56. exit 0;
  57.  
  58.